/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */

package com.haulmont.asu.entity;

import com.haulmont.chile.core.annotations.MetaProperty;
import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.StandardEntity;

import javax.persistence.*;
import java.util.List;

/**
 * Author: Sergey42
 * Date: 17.10.13 14:03
 */
@Table(name = "ASU_PHASE")
@Entity(name = "asu$Phase")
@NamePattern("%s|xName")
public class Phase extends StandardEntity {

    private static final long serialVersionUID = -789990750547692482L;

    @Column(name = "NAME", length = 50)
    protected String name;

    @Column(name = "PHASE_ORDER")
    protected Integer order;

    @OneToMany(mappedBy = "phase")
    @OrderBy("order")
    protected List<Stage> stages;

    @ManyToOne
    @JoinColumn(name = "PROJECT_ID")
    protected Project project;

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    @MetaProperty
    public String getXName() {
        return order != null ? "[" + order + "] " + name : "[] " + name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public List<Stage> getStages() {
        return stages;
    }

    public void setStages(List<Stage> stages) {
        this.stages = stages;
    }
}
